$(function(){
	transRefund();
});

function transRefund(){
	$('#button').unbind('click');
	$('#button').bind('click',function(){
		var customerNoReg = /^[0-9]+$/;
		var merKeyReg = /^[A-Za-z0-9]+$/;
		var amountReg = /^(([1-9]{1}\d*)|([0]{1}))(\.(\d){1,2})?$/;
		var customerNo = $('#customerNo').val();
		var tradeNo = $('#tradeNo').val();
		var orderNo = $('#orderNo').val();
		var amount = $('#amount').val();
		var merKey = $('#merKey').val();
		if (!customerNoReg.test(customerNo)) {
			alertMsg('请输入正确的商户号!');
			return;
		}
		if (!customerNoReg.test(tradeNo)) {
			alertMsg('请输入正确的流水号!');
			return;
		}
		if (!customerNoReg.test(orderNo)) {
			alertMsg('请输入正确的订单号!');
			return;
		}
		if (!amountReg.test(amount)) {
			alertMsg('请输入正确的退款金额!');
			return;
		}
		if (!merKeyReg.test(merKey)) {
			alertMsg('请输入正确的merKey!');
			return;
		}
		
		var params = {
				customerNo:customerNo,
				tradeNo:tradeNo,
				orderNo:orderNo,
				amount:amount,
				merKey:merKey
		};
		var reqUrl = '../refund/transRefund';
		$.ajax({
			url: reqUrl,
			type: 'POST',
			//同步执行
			async:false,
			data: params,
			dataType: 'json',
			success: function(data) {
				$('#result').text(JSON.stringify(data));
			},
			error: function(data) {
				alertMsg("未知错误");
			}
		});
		
	});
}

function alertMsg(msg){
	var params = {
	    container : {
		    content :msg
		  },
		autoClose : 1500
	};
	easyDialog.open(params);
}